#!/usr/bin/python
# -*- coding: UTF-8 -*-

import MySQLdb

from tools import excel_reader


def judge(cards):
    # 打开数据库连接
    db = MySQLdb.connect("192.168.199.11", "liujinxia", "ljx@888", "schoolmate", charset='utf8')

    # 使用cursor()方法获取操作游标
    cursor = db.cursor()

    # 使用execute方法执行SQL语句
    # cursor.execute("SELECT VERSION()")
    # cursor.execute("SELECT 1 FROM s_schoolmate where card = " + card)
    for card in cards:
        cursor.execute("SELECT 1 FROM s_schoolmate WHERE card = %s", (card,))

        # 使用 fetchone() 方法获取一条数据
        data = cursor.fetchone()
        print("fetch:{s} ", card)
        if (data is None):
            print(card)
        if (data is not None and data[0] != 1):
            print(" %s " % data)
            print(" %s " % card)

    # 关闭数据库连接
    db.close()


if __name__ == '__main__':
    array = excel_reader.read()
    judge(array)
